package common;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.TopicConnectionFactory;
import java.util.Objects;

/**
 * Created with Intel IDEA.
 * 消息静态工厂
 *
 * @Auther: gjt
 * @Date: 2024/11/3 9:35
 */
public class MessageConnectionFactory {

    private static String USERNAME = ActiveMQConnection.DEFAULT_USER;
    private static String PASSWORD = ActiveMQConnection.DEFAULT_PASSWORD;
    private static String BROKER = ActiveMQConnection.DEFAULT_BROKER_URL;

    private volatile static TopicConnectionFactory conFactory = null;


    private MessageConnectionFactory(){}

    /**
     *  赖汉双检索
     */
    public static TopicConnectionFactory getInstance(){
        if(Objects.isNull(conFactory)){
            synchronized (MessageConnectionFactory.class){
                if(Objects.isNull(conFactory)){
                    conFactory = new ActiveMQConnectionFactory(USERNAME, PASSWORD, BROKER);
                }
            }
        }
        return conFactory;
    }


}
